(function () {
    line()
    var d = false
    var mychart = echarts.init(document.getElementById('consumeDaily'))
    $('.consumeDaily button').on('click', function () {
        $(this).removeClass('nofocus').addClass('focus')
        $(this).siblings().removeClass('focus').addClass('nofocus')
        mychart.clear()
        if ($(this).attr('consumeId') == 1) {
            block()
        } else {
            line()

        }
    })
    //  
    function line() {
        if (d) {
            return
        }
        d = true
        var option = {
            color: ['#2B99FF', '#23F2E6'],
            legend: {
                data: [],
                right: '3%',
                top: '5%',
                textStyle: {
                    color: 'rgba(39,42,46， 0.5)'
                }
            },
            tooltip: {
                trigger: 'item',

            },
            xAxis: {
                type: 'category',
                axisLine: {
                    show: false
                },
                boundaryGap: false,

                data: ['早餐', '午餐', '晚餐', '夜餐'],
                axisLabel: {
                    textStyle: {
                        color: '#838687',
                        fontSize: '10'
                    },
                    interval: 0,
                }
            },
            yAxis: {
                show: false,
                inverse: false,
                axisLabel: {
                    textStyle: {
                        color: '#838687',
                        fontSize: '10'
                    },
                    interval: 0,
                },
            },
            series: [

            ]
        };
        $.ajax({
            url: info.base_url + '/ccp/CardController/perCapitaConsume',
            dataType: 'json',
            type: 'post',
            data: {
                time: info.queryTime,
                token: info.token
            },
            success: function (res) {
                const obj = JSON.parse(res.object)
                for (var i in obj) {
                    option.series.push({
                        data: obj[i].map(function (e) {
                            return -e.sum
                        }),
                        type: 'line',
                        name: obj[i][0].groupname
                    })
                    option.legend.data.push(obj[i][0].groupname)
                }
                mychart.setOption(option)
                d = false
            }
        })
    }
    function block() {
        if (d) {
            return
        }
        d = true
        var itemStyle = {
            normal: {
            },
            emphasis: {
                barBorderWidth: 1,
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowColor: 'rgba(0,0,0,0.5)'
            }
        };
        var option = {
            legend: {
                data: [
                    '现金', '福利费', '消费现金金额', '消费福利金额'
                ],
                right: '1%',
                top: '3%',
                textStyle: {
                    color: 'rgba(255,255,255,0.8)'
                }
            },
            color: ['#23F9EC', '#225566'],

            tooltip: {
                trigger: 'item',

            },
            grid: {
                left: '3%',
                right: '3%',
                bottom: '0%',
                top: '20%',
                containLabel: true
            },

            xAxis: {
                data: [],
                silent: false,
                axisLine: { onZero: true },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: '#585858'
                    },
                    interval: 1.5
                },
                // splitArea: { show: false },
                axisLabel: {
                    textStyle: {
                        color: '#838687',
                        fontSize: '10'
                    },
                    // interval: 0,
                }
            },
            yAxis: {
                inverse: false,
                axisLabel: {
                    textStyle: {
                        color: '#838687',
                        fontSize: '10'
                    },
                    interval: 0,
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: '#585858'
                    }
                },
            },
            series: [
            ]
        };
        $.ajax({
            url: info.base_url + '/ccp/MonitoringCenterController/transferResumeMethod',
            dataType: 'json',
            type: 'post',
            data: {
                method: '/consume/chart/dayConsumeMoney',
                json: JSON.stringify({
                    queryTime: info.queryTime,
                    ids: '12,13'
                }),
                token: info.token
            },
            success: function (res) {
                const obj = res.object.list2.slice(15)
                option.xAxis.data = obj.map(function (e) {
                    return e.consumetime
                })
                option.series.push({
                    data: obj.map(function (e) {
                        return -e.consumemoney
                    }),
                    type: 'bar',
                    name: '消费现金金额',
                    stack: 'one'
                })
                option.series.push({
                    data: obj.map(function (e, i) {
                        return {
                            value: -e.subconsumemoney - option.series[0].data[i],
                            tooltip:{
                                trigger: 'item',
                                formatter: '{a} {b} :' + -e.subconsumemoney
                            }
                        }
                    }),
                    type: 'bar',
                    name: '消费福利金额',
                    stack: 'one'
                })

                $.ajax({
                    url: info.base_url + '/ccp/MonitoringCenterController/transferResumeMethod',
                    dataType: 'json',
                    type: 'post',
                    data: {
                        method: '/consume/chart/dayConsumeMoney',
                        json: JSON.stringify({
                            queryTime: info.queryTime,
                            ids: '0154021001,0157390415,0157390769'
                        }),
                        token: info.token
                    },
                    success: function (res) {
                        console.log(res)
                        const obj = res.object.list2.slice(15)
                        option.xAxis.data = obj.map(function (e) {
                            return e.consumetime
                        })
                        option.series.push({
                            data: obj.map(function (e) {
                                return -e.consumemoney
                            }),
                            type: 'line',
                            name: '现金',
                            lineStyle: {
                                color: '#2B99FF'
                            }
                        })
                        option.series.push({
                            data: obj.map(function (e, i) {
                                return -e.subconsumemoney 
                            }),
                            type: 'line',
                            name: '福利费',
                            lineStyle: {
                                color: '#F8B136'
                            }
                        })
                        mychart.setOption(option)
                        d = false
                    }
                })

            }
        })
    }
})()